package org.ceteca.explica.core.common;

import java.rmi.Remote;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.ceteca.explica.core.ExplicaException;
import org.ceteca.explica.core.partners.AddressOT;
import org.ceteca.explica.core.util.OperationResult;
import org.ceteca.explica.core.util.ResultMessage;

import org.ceteca.explica.core.common.BarcodeTypeOT;
import org.ceteca.explica.core.common.VatTypeOT;
import org.ceteca.explica.core.extTables.ExtFieldOT;
import org.ceteca.explica.core.extTables.ExtTableDAO;
import org.ceteca.explica.core.extTables.ExtTableException;
import org.ceteca.explica.core.extTables.ExtTableOT;
import org.ceteca.explica.server.util.db.CriteriaBean;
import org.hibernate.criterion.Criterion;

public interface CommonManager extends Remote {
	public List queryBarcodeTypes(String fieldId, String value) throws RemoteException, ExplicaException;
	public OperationResult delBarcodeType(Long idBarcodeType) throws RemoteException, ExplicaException;
	public OperationResult delBarcodeTypes(ArrayList<Long> lSelBarcodeTypes) throws RemoteException, ExplicaException;
	public OperationResult saveBarcodeType(BarcodeTypeOT barcodeType) throws RemoteException, ExplicaException;
	public BarcodeTypeOT getBarcodeType(Long idBarcodeType) throws RemoteException, ExplicaException;
	
	public List queryVatTypes(String fieldId, String value) throws RemoteException, ExplicaException;
	public OperationResult delVatType(Long idVatType) throws RemoteException, ExplicaException;
	public OperationResult delVatTypes(ArrayList<Long> lSelVatTypes) throws RemoteException, ExplicaException;
	public OperationResult saveVatType(VatTypeOT vatType) throws RemoteException, ExplicaException;
	public VatTypeOT getVatType(Long idVatType) throws RemoteException, ExplicaException;
	/*
	public List queryAddresses(String fieldId, String value) throws RemoteException, ExplicaException;
	public OperationResult delAddress(Long idAddress) throws RemoteException, ExplicaException;
	public OperationResult delAddresses(ArrayList<Long> lSelAddresses) throws RemoteException, ExplicaException;
	public OperationResult saveAddress(AddressOT address) throws RemoteException, ExplicaException;
	public AddressOT getAddress(Long idAddress) throws RemoteException, ExplicaException;
	*/
	/**
	 * Return the extension table definition, including the list of all the
	 * extension fields defined for the table.
	 * @param codExtTable String, external code of the extension table.
	 * @return ExtTableOT, extension table definition.
	 * @throws ExtTableException in case any error take place during the
	 * query operation.
	 */
	public ExtTableOT getExtensionTableDefinition(String codExtTable) throws RemoteException, ExtTableException;

	
	/**
	 * Return all the values stored for an extended item. Include all the fields
	 * defined for the extension table and their correspondent value (if anyone 
	 * has been defined).
	 * @param idValue Long, internal id of the extended item. 
	 * @param codExtTable String, external code of the extension table.
	 * @return Map, set of all the extension fields and their values for the 
	 * extended item.
	 * @throws ExtTableException, in case any error take place during the query 
	 * operation.
	 */
	public Map getExtendedItemValues(Long idValue, String codExtTable) throws RemoteException, ExtTableException;
	
	/**
	 * Update the value of all the extension fields defined for an extended item.
	 * @param lExtFields ArrayList, list of all the extension fields whose values
	 * must be updated.
	 * @param idItem long, internal id of the extended item.
	 * @return OperationResult, result of the save extended values operation.
	 * @throws ExtTableException, in case any error take place during
	 * the update operation.
	 */
	public OperationResult saveExtendedItemValues(ArrayList lExtFields, long idItem) throws RemoteException, ExtTableException;
	
	/**
	 * Update the value of all the extension fields defined for an extended item.
	 * @param mExtFields Map, set of all the extension fields whose values
	 * must be updated.
	 * @param idItem long, internal id of the extended item.
	 * @throws ExtTableException, in case any error take place during
	 * the update operation.
	 */
	public void saveExtendedItemValues(Map mExtFields, long idItem) throws RemoteException, ExtTableException;
	
	
	
	
	public List<BaseVO> queryEntities(String fieldId, String value, Class myClass) throws ExplicaException, RemoteException;
	public BaseVO getEntity(Long id, Class myClass) throws RemoteException, ExplicaException;
	//public OperationResult delEntity(Long id, Class myClass) throws RemoteException, ExplicaException;
	public OperationResult saveEntity(BaseVO entity) throws RemoteException, ExplicaException;
	public OperationResult delEntities(ArrayList<Long> lSel, Class myClass) throws RemoteException, ExplicaException;
	//public OperationResult delEntity(BaseVO entity) throws RemoteException, ExplicaException;
	
	public List<BaseVO> queryEntities(String fieldId, BaseVO value, Class myClass) throws RemoteException, ExplicaException;
	public OperationResult delEntity(BaseVO b) throws RemoteException, ExplicaException;
	public List<BaseVO> queryEntities(String  sql) throws RemoteException, ExplicaException;
	public BaseVO getEntity(String fieldId, String value, Class myClass) throws ExplicaException, RemoteException;
	
	public OperationResult saveImage(String imgName, byte[] contents) throws RemoteException, ExplicaException;
}